package com.sgq.vue.controller.monitor;

import com.sgq.vue.annotation.Log;
import com.sgq.vue.entity.monitor.SysJobLog;
import com.sgq.vue.enums.BusinessType;
import com.sgq.vue.result.Result;
import com.sgq.vue.service.monitor.ISysJobLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 调度日志操作处理
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/monitor/jobLog")
public class SysJobLogController
{
    @Autowired
    private ISysJobLogService jobLogService;

    /**
     * 查询定时任务调度日志列表
     */
    @PreAuthorize("hasAuthority('monitor:job:list')")
    @GetMapping("/list")
    public Result list(SysJobLog sysJobLog)
    {
        List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog);
        return Result.ok(list);
    }

    /**
     * 导出定时任务调度日志列表
     */
    @PreAuthorize("hasAuthority('monitor:job:export')")
    @Log(title = "任务调度日志", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public Result export(SysJobLog sysJobLog)
    {

        return Result.ok();
    }
    
    /**
     * 根据调度编号获取详细信息
     */
    @PreAuthorize("hasAuthority('monitor:job:query')")
    @GetMapping(value = "/{configId}")
    public Result getInfo(@PathVariable Long jobLogId)
    {
        return Result.ok(jobLogService.selectJobLogById(jobLogId));
    }


    /**
     * 删除定时任务调度日志
     */
    @PreAuthorize("hasAuthority('monitor:job:remove')")
    @Log(title = "定时任务调度日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{jobLogIds}")
    public Result remove(@PathVariable Long[] jobLogIds)
    {
        return Result.ok(jobLogService.deleteJobLogByIds(jobLogIds));
    }

    /**
     * 清空定时任务调度日志
     */
    @PreAuthorize("hasAuthority('monitor:job:remove')")
    @Log(title = "调度日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public Result clean()
    {
        jobLogService.cleanJobLog();
        return Result.ok();
    }
}
